#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define BUFFSIZE 20
int main(){
    char buff[BUFFSIZE];

    int file_id = open("fwrite.txt", O_CREAT | O_WRONLY | O_TRUNC, 0777);
    if(file_id < 0){
        perror("open");
        return -1;
    }


    while(fgets(buff, BUFFSIZE, stdin) != NULL){
        if(strcmp(buff, "quit\n") == 0){
            break;
        }

        //写入文件
        write(file_id, buff, strlen(buff));
    }

    close(file_id);
    return 0;
}